<?php
$optionPostCate = "";
foreach($aPostCate as $pc){
    $optionPostCate .= "<option value='{$pc->getId()}'>{$pc->getTitle()}</option>";
}
$aRole = unserialize(ROLE_NAME);
?>

<div class="row">
	<div class="col-md-12">
		<h1>Tin tức <small>Quản lý các tin tức</small></h1>
		<ol class="breadcrumb">
            <li><a href="<?php echo admin_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="<?php echo admin_page_url(POST_SLUG); ?>"><i class="fa fa-table"></i> Tin tức</a></li>
        </ol>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-xs-12">
        <form method="get" action="<?php echo admin_page_url(POST_SLUG.'/tim-kiem'); ?>" enctype="multipart/form-data">
            <div class="input-group">
                <input type="text" class="form-control" name="s" value="<?php echo isset($searchkey)?$searchkey:''; ?>" placeholder="Tìm kiếm" />
                <span class="input-group-btn">
                    <button class="btn btn-success" type="submit"><i class="fa fa-search"></i> Tìm kiếm!</button>
                </span>
            </div><!-- /input-group -->
        </form>
    </div>

    <div class="col-md-6 col-xs-12">
        <p class="pull-right">
            <a class="btn btn-success" href="<?php echo admin_page_url(POST_SLUG.'/them'); ?>"><i class="glyphicon glyphicon-plus-sign"></i> Thêm tin tức</a>
            <a class="btn btn-default" href="<?php echo admin_page_url(POST_SLUG, array('f'=>'trash')); ?>"><i class="fa fa-trash-o"></i> Không hiển thị</a>
        </p>
    </div>
    <div class="clearfix"></div>

    <div class="col-md-12 col-xs-12">
        <?php echo $pagingBar; ?>
    </div>

    <div class="col-md-12 mgt5">
        <div class="table-responsive">
            <table class="table table-bordered table-hover tablesorter item-list" data-href='<?php echo admin_page_url(POST_SLUG.'/cap-nhat'); ?>'>
                <thead>
                    <tr>
                        <th class="header"># <i class="fa fa-sort"></i></th>
                        <th class="header">Hình ảnh</th>
                        <th class="header">Thông tin <i class="fa fa-sort"></i></th>
                        <th class="header">Mô tả <i class="fa fa-sort"></i></th>
                        <th class="header">&nbsp;</th>
                    </tr>
                    <tr class="tr-temp hidden warning">
                        <td colspan="7">
                            <form role="form" method="post" data-callback="1">
                                <div class="col-md-6 col-xs-12">
                                    <div class="form-group">
                                        <label for="input-post-title">Tiêu đề</label>
                                        <input type="text" class="form-control auto-slug" follow-ctr='#input-post-slug' id="input-post-title" name="post[title]" />
                                    </div>
                                    <div class="form-group">
                                        <label for="input-post-slug">Đường dẫn</label>
                                        <input type="text" class="form-control" id="input-post-slug" name="post[slug]" />
                                    </div>
                                    <div class="form-group">
                                        <label for="input-post-cate">Danh mục</label>
                                        <select class="form-control" id="input-post-cate" name="post[cate]">
                                            <?php echo $optionPostCate; ?>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <label for="input-post-order">Thứ tự</label>
                                        <input type="text" class="form-control" id="input-post-order" name="post[order]" />
                                    </div>
                                </div>
                                <div class="col-md-6 col-xs-12">
                                    <div class="form-group">
                                        <label for="input-post-description">Mô tả</label>
                                        <textarea rows="6" class="form-control" id="input-post-description" name="post[description]"></textarea>
                                    </div>
                                    <div class="form-group">
                                        <div class="checkbox">
                                            <label for="input-post-publish-flg">
                                                <input type="checkbox" id="input-post-publish-flg" name="post[publish_flg]" value="1" />Hiển thị
                                            </label>
                                        </div>
                                        <div class="checkbox">
                                            <label for="input-post-delete-flg">
                                                <input type="checkbox" id="input-post-delete-flg" name="post[delete_flg]" value="1"/> Xoá
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <input type="hidden" name="post[case]" value="<?php echo UPDATE_CASE_LIST; ?>"/>
                                        <input type="hidden" name="post[id]" id="input-post-id" />
                                        <button type="button" class="btn btn-success btn-submit-update"><i class="glyphicon glyphicon-ok-sign"></i> Cập nhật</button>
                                        <button type="button" class="btn btn-danger btn-cancel-update"><i class="glyphicon glyphicon-remove-sign"></i> Huỷ</button>
                                    </div>
                                </div>
                            </form>
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($aPost as $index=>$post) { ?>
                    <tr class="can-edit" data-id="<?php echo $this->encrypt->encode($post->getId()); ?>">
                        <th class="header bg-info"><?php echo $index+1; ?></th>
                        <td class="col-md-3">
                            <div class="media">
                                <?php if($post->getImage()!='' && image_exist('public/'.$post->image_folder.'/'.POST_IMAGE_URL.$post->getImage())) { ?>
                                <a class="thumbnail" href="<?php echo admin_post_url($post->getSlug()); ?>" title="<?php echo $post->getTitle(); ?>">
                                    <img class="has-border" src="<?php echo post_upload($post->getImage(), $post->image_folder); ?>" />
                                </a>
                                <?php } else { ?>
                                <a class="thumbnail" href="#" title="blank">
                                    <img data-src="holder.js/300x168" class="media-object" />
                                </a>
                                <?php } ?>
                            </div>
                        </td>
                        <td>
                            <h4>
                                <a class="input-post-title strong big-title" href="<?php echo admin_post_url($post->getSlug()); ?>"><?php echo $post->getTitle(); ?></a>
                            </h4>
                            <h4>
                                <a data-post-cate="<?php echo $post->post_cate_id; ?>" class="input-post-cate clear-decoration"
                                    href="<?php echo admin_post_cate_url($post->post_cate_slug); ?>">
                                    <label class="label label-danger">
                                        <?php echo $post->post_cate_title; ?>
                                    </label>
                                </a>
                            </h4>
                            <p><?php echo $post->user_full_name; ?> ( <span class="<?php echo $post->role==ROLE_ADMIN?'admin':'mod'; ?>"><?php echo $aRole[$post->role]; ?></span> )</p>
                            <p><?php echo fdate_format($post->getCreatedAt()); ?></p>
                            <p class="strong"><span class="input-post-order"><?php echo $post->getOrder(); ?></span></p>
                        </td>
                        <td class="input-post-description w200"><?php echo $post->getDescription(); ?></td>
                        <td>
                            <p class="checkbox">
                                Hiển thị
                                <input id="chk-publish-<?php echo $index+1; ?>" class="input-post-publish-flg lb-toggle" data-name="publish_flg" type="checkbox"
                                <?php echo $post->getPublishFlg()!=NULL && $post->getPublishFlg()==1 ?"checked='checked'":''; ?> />
                                <label for="chk-publish-<?php echo $index+1; ?>"></label>
                            </p>
                            <p class="checkbox">
                                Xoá
                                <input id="chk-del-<?php echo $index+1; ?>" class="input-post-delete-flg lb-toggle red" data-name="delete_flg" type="checkbox"
                                <?php echo $post->getDeletedAt()!=NULL && $post->getDeletedAt()!='' ?"checked='checked'":''; ?> />
                                <label for="chk-del-<?php echo $index+1; ?>"></label>
                            </p>
                            <a class="btn btn-success input-post-slug mgt5" target="_blank" data-slug="<?php echo $post->getSlug(); ?>" data-href="<?php echo post_single_url('{replace_slug}'); ?>" href="<?php echo post_single_url($post->getSlug()); ?>">
                                <i class="glyphicon glyphicon-share-alt"></i> Xem
                            </a>
                            <a class="btn btn-primary mgt5" href="<?php echo admin_post_url($post->getSlug()); ?>">
                                <i class='glyphicon glyphicon-pencil'></i> Cập nhật
                            </a>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="clearfix"></div>
</div>